﻿unit uFrmAbout;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Imaging.pngimage;

type
  TFrmAbout = class(TForm)
    imgAbout: TImage;
    btnClose: TButton;
    lblProductName: TLabel;
    lblProductVersion: TLabel;
    lblCopyright: TLabel;
    procedure btnCloseClick(Sender: TObject);
    // procedure CreateParams(var Params: TCreateParams); override;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmAbout: TFrmAbout;

implementation

uses
  uFrmMain;

{$R *.dfm}

function GetBuildInfo(): string; overload;
var
  VerInfoSize, VerValueSize, Dummy: DWORD;
  VerInfo: Pointer;
  VerValue: PVSFixedFileInfo;
  V1, V2, V3, V4: Word;
begin
  VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
  if VerInfoSize = 0 then
    Exit;
  GetMem(VerInfo, VerInfoSize);
  if not GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo) then
    Exit;
  VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
  with VerValue^ do
  begin
    V1 := dwFileVersionMS shr 16;
    V2 := dwFileVersionMS and $FFFF;
    V3 := dwFileVersionLS shr 16;
    V4 := dwFileVersionLS and $FFFF;
  end;
  Result := IntToStr(V1) + '.' + IntToStr(V2) + '.' + IntToStr(V3) + '.' + IntToStr(V4);
  FreeMem(VerInfo, VerInfoSize);
end;

procedure TFrmAbout.btnCloseClick(Sender: TObject);
begin
  Close;
end;

{
  procedure TFrmAbout.CreateParams(var Params: TCreateParams);
  begin
  inherited;
  Params.WndParent := 0;
  end;
}

procedure TFrmAbout.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TFrmAbout.FormCreate(Sender: TObject);
var
  iTop, iLeft: Integer;
begin
{$IFDEF WIN64}
  lblProductName.Caption := 'Product Name: SuperTREX64.exe';
{$ELSE}
  lblProductName.Caption := 'Product Name: SuperTREX32.exe';
{$ENDIF}
  lblProductVersion.Caption := 'Product Version: V' + GetBuildInfo;
  lblCopyright.Caption := 'Copyright © 2022 SUPER_紫电.All Rights Reserved.';
  //
  iTop := FrmMain.Top;
  iLeft := FrmMain.Left;
  if iTop > Height then
  begin
    Top := iTop - Height;
    Left := iLeft;
  end;
end;

procedure TFrmAbout.FormDestroy(Sender: TObject);
begin
  FrmAbout := nil;
end;

end.

